<template>
	<view class="box">
		<my-list :myList='myList' @setWifiPlay="setWifiPlay" @setWifiDownload="setWifiDownload"
			@setAutoPlay="setAutoPlay" @clearStorage="clearStorage"></my-list>
	</view>
</template>

<script>
	import MyList from "@/mock/setting-list-bar.js"
	import myList from '@/pages/mine/components/my-list'
	export default {
		data() {
			return {
				myList: MyList()
			}
		},
		methods: {
			clearStorage(obj) {
				console.log(obj)
			        uni.showModal({
			          title: "你确定你要删除应用缓存吗？",
			          content: '该操作不会删除缓存课程',
			          success: (res) => {
			            if (res.confirm) {
			              uni.clearStorage()
			              this.$set(obj, 'text', '0kb')
			              uni.showLoading({
			                title:'删除成功',
			              })
			              setTimeout(function(){
			                uni.hideLoading()
			              },500)
			            }
			          }
			        })
			      },
				  // 允许WIFI网络缓存
			      setWifiPlay(obj){
			        this.saveStorage(obj,'wifi-play')
			      },
				  // 允许非WIFI网络缓存
				   setWifiDownload(obj) {
				   this.saveStorage(obj, 'wifi-download')
				   },
				   
				   // 视频自动连续播放
				   setAutoPlay(obj) {
				   this.saveStorage(obj, 'auto-play')
				   },
			      //保存到本地
			      saveStorage(obj,key){
			        console.log(key)
			        const checked=!obj.checked
			        this.$set(obj,'checked',checked)
			        //保存到本地
			        uni.setStorage({
			          key,
			          data:checked
			        })
			        console.log('修改后的状态值')
			      }
		},
		components: {
			myList
		}
	}
</script>

<style lang='scss'>

</style>
